#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# ======================================================
# @File:      : test128
# @Author     : forward_huan
# @Date       : 2024/11/16 17:22
# @Desc       :
# ======================================================
from typing import List


class Solution:
    def longestConsecutive(self, nums: List[int]) -> int:
        if len(nums) <= 1:
            return len(nums)
        nums.sort()
        nums.append(nums[0])
        max_len, cur_start = 1, 0
        for i in range(1, len(nums)):
            if nums[i] - nums[i - 1] == 1:
                continue
            if nums[i] == nums[i - 1]:
                cur_start += 1
                continue
            max_len = max(max_len, i - cur_start)
            cur_start = i
        return max_len


# print(Solution().longestConsecutive(nums=[100, 4, 200, 1, 3, 2]))
print(Solution().longestConsecutive([0, 3, 7, 2, 5, 8, 4, 6, 0, 1]))
print(Solution().longestConsecutive([1, 2, 0, 1]))
